export default {
  namespaced: true,
  state: () => ({
    token: uni.getStorageSync('token'),
    oid: uni.getStorageSync('oid'),
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || null),
    userImg: uni.getStorageSync('userPic') || 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
    yhq_num: 0,
    order_num: 0,
    map_sc_num: 0,
    isPhone:''
  }),
  getters: {
    yhq_num: state => state.yhq_num,
    order_num: state => state.order_num,
    map_sc_num: state => state.map_sc_num,
    userImg_show:state=>state.userImg,
    token_change:state=>state.token
  },
  mutations: {
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo
      // 通过 this.commit() 方法，调用 m_user 模块下的 saveUserInfoToStorage 方法，将 userinfo 对象持久化存储到本地
      this.commit('m_user/saveUserInfoToStorage')
    },
    updataIsPhone(state,val){
       state.isPhone = val
    },
    updateUserPic(state, val) {
      state.userImg = val
      // 通过 this.commit() 方法，调用 m_user 模块下的 saveUserInfoToStorage 方法，将 userinfo 对象持久化存储到本地
      this.commit('m_user/saveUserImg')
    },
    saveUserImg(state) {
      uni.setStorageSync('userPic', state.userImg)
    },
    // 将 userinfo 持久化存储到本地
    saveUserInfoToStorage(state) {
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
    // 更新 token 字符串
    updateToken(state, token) {
      state.token = token
      // 通过 this.commit() 方法，调用 m_user 模块下的 saveTokenToStorage 方法，将 token 字符串持久化存储到本地
      this.commit('m_user/saveTokenToStorage')
    },
    //设置openid
    updateOid(state, oid) {
      state.oid = oid
      // 通过 this.commit() 方法，调用 m_user 模块下的 saveTokenToStorage 方法，将 token 字符串持久化存储到本地
      this.commit('m_user/saveOidToStorage')
    },
    //存储openid
    saveOidToStorage(state) {
      uni.setStorageSync('oid', state.oid)
    },
    //设置uid
    updateUid(state, uid) {
      state.uid = uid
      // 通过 this.commit() 方法，调用 m_user 模块下的 saveTokenToStorage 方法，将 token 字符串持久化存储到本地
      this.commit('m_user/saveUidToStorage')
    },
    //存储unid
    saveUidToStorage(state) {
      uni.setStorageSync('uid', state.uid)
    },
    // 将 token 字符串持久化存储到本地
    saveTokenToStorage(state) {
      uni.setStorageSync('token', state.token)
    },
    clearStorage(state){
      uni.clearStorage()
      state.token='';
    },
    updateYhqNum(state, val) {
      state.yhq_num = val
    },
    updateOrderNum(state, val) {
      state.order_num = val
    },
    updateMapScNum(state, val) {
      state.map_sc_num = val
    }
  }
}
